package com.ajieee.merge.runner.finance;

import com.ajieee.merge.entity.finance.po.StockQuotePO;
import com.ajieee.merge.enums.finance.EtlType;
import com.ajieee.merge.enums.finance.Exchange;
import com.ajieee.merge.mapper.StockQuoteMapper;
import com.ajieee.merge.runner.finance.proxy.SzseProxy;
import lombok.RequiredArgsConstructor;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author ajieee
 * @date 2025-10-13
 */
@Order(EtlOrder.QUOTE_ORDER)
@Component
@RequiredArgsConstructor
public class SzseStockQuoteEtl extends AbstractEtl {

	private final StockQuoteMapper stockQuoteMapper;

	private final SzseProxy szseProxy;

	@Override
	public void doExecute() {
		List<StockQuotePO> quotes = szseProxy.getSzseStockQuotes(getTradeDate());
		if (!quotes.isEmpty()) {
			stockQuoteMapper.deleteByDataDateAndExchange(getTradeDate(), Exchange.SZSE);
			stockQuoteMapper.insert(quotes);
		}
	}

	@Override
	public EtlType getType() {
		return EtlType.SZSE_STOCK_QUOTE;
	}
}
